#下标
name="abcdefg"
print(name[2:5:1])
print(name[2:5])
print(name[:5])
print(name[1:])
print(name[:])
print(name[::2])
print(name[:-1])
print(name[-4:-1])
print(name[::-1])

#查找
mystr="hello world and supertest and chaoge and Python "

print(mystr.find('and'))     #12
print(mystr.find('and',15,30))   #27
print(mystr.find('ands'))   #-1

print(mystr.index('and'))   #12
print(mystr.index('and',15,30))   #27
# print(mystr.index('ands'))    #报错

print(mystr.count('and'))   #3
print(mystr.count('ands'))     #0
print(mystr.count('and',0,20))    #1

#replace()  替换字符串
print(mystr.replace("and","he")) #结果：hello world he superctest he chaoge he Python
print(mystr.replace("and","he",10))      #结果：hello world he superctest he chaoge he Python
print(mystr)    #结果：hello world and superctest and chaoge and Python

#按照指定字符分割字符串
print(mystr.split('and'))    #结果：['hello world','supertest','chaoge','Python']
print(mystr.split('and',2))     #结果：['hello world','supertest','chaoge and Python']
print(mystr.split(' '))      #结果：['hello','world','and','supertest','and','chaoge','and','Python'
print(mystr.split(' ',2))    #结果：['hello','world','and supertest and chaoge and Python']

# join()，用一个字符或子串合并字符串，即时将多个字符串合并为一个新的字符串
list1=['chao','ge','test','promotion']
t1=('aa','b','cc','ddd')
print('_'.join(list1))    #chao_ge_test_promotion
print('...'.join(t1))     #aa...b...cc...ddd

#caplitalize():将字符串第一个字符转换成大写
print(mystr.capitalize())    #Hello world and supertest and chaoge and python

#title():将字符串中每一个字符的首字母大写
print(mystr.title())      #Hello World And Supertest And Chaoge And Python

# lower():将字符串中大写转小写
print(mystr.lower())     #hello world and supertest and chaoge and python

#upper():将字符串中的小写转大写
print(mystr.upper())       #HELLO WORLD AND SUPERTEST AND CHAOGE AND PYTHON

#lstrip():删除字符串左侧空白字符
mystr1=" hello world and supertest and chaoge and Python "
print(mystr1.lstrip())    #hello world and supertest and chaoge and Python

#rstrip():删除字符串右侧空白字符
print(mystr1.rstrip())    # hello world and supertest and chaoge and Python

#strip():删除字符串两侧空白字符
print(mystr1.strip())    #hello world and supertest and chaoge and Python

# ljust():返回一个原字符串左对齐，并使用指定字符填充至对应长度的新字符串
mystr2='hello'
mystr2.ljust(10,'.')    #'hello.....'

#rjust():返回一个原字符串右对齐，并使用指定字符填充至对应长度的新字符串
mystr2.rjust(10,'.')     #'.....hello'

#center():返回一个原字符串居中对齐，并使用指定字符填充至对应长度的新字符串
mystr2.center(10,'.')       #..hello...

#判断
#startswith():检查字符串是否时以指定子串开头，是则返回True，否则返回False
print(mystr.startswith('hello'))
print(mystr.startswith('hello',5,20))

#endswith():检查字符串是否时以指定子串结尾，是则返回True，否则返回False
print(mystr.endswith("Python"))   #True
print(mystr.endswith("python"))    #False
print(mystr.endswith('Python',2,20))   #False

#isalpha():如果字符串至少有一个字符并且所有字符都是字母则返回True，否则返回False
str1='hello'
str2='hello1234'
print(str1.isalpha())     #True
print(str2.isalpha())     #False

#isdigit():如果字符串只包含数字则返回True，否则返回False
print(str1.isdigit())    #False
print(str2.isdigit())    #False

# isalnum():如果字符串至少有一个字符并且所有字符都是字母或数字则返回True，否则返回False

#isspace():如果字符串中只包含空白，则返回True，否则返回False